const drag = {
  beforeMount (el, binding, vnode) {
    var oDiv = el
    oDiv.onmousedown = function (ev) {
      // 定位差
      var disX = ev.clientX - oDiv.offsetLeft
      var disY = ev.clientY - oDiv.offsetTop
      document.onmousemove = function (ev) {
        var l = ev.clientX - disX
        var t = ev.clientY - disY
        if (l < 0) {
          l = 0
        } else if (l > window.innerWidth - oDiv.offsetWidth - 258) {
          l = window.innerWidth - oDiv.offsetWidth - 258
        }
        if (t < 0) {
          t = 0
        } else if (t > window.innerHeight - oDiv.offsetHeight - 90) {
          t = window.innerHeight - oDiv.offsetHeight - 90
        }
        oDiv.style.left = l + 'px'
        oDiv.style.top = t + 'px'
      }
      document.onmouseup = function () {
        document.onmousemove = null
        document.onmouseup = null
      }
    }
  }
}

const directives = {
    install: function (app) {
      app.directive("drag", drag);
    }
  };

  export default directives;